﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using echarts.data.DataModel;
using echarts.data.Entity;
using SqlSugar;

namespace echarts.data
{
    public class ProductDao
    {
        public static int AddProductData(ProductData data)
        {
            return DataBase.Instance.Insertable<ProductData>(data).ExecuteReturnIdentity();
        }

        public static bool DeleteById(int id)
        {
            return DataBase.Instance.Deleteable<ProductData>(it => it.Id == id).ExecuteCommand() > 0;
        }

        public static List<ProductPageModel> GetDataGroupByProvice()
        {
            return DataBase.Instance.Queryable<ProductData>().GroupBy(x => x.Province)
                .Select(m => new ProductPageModel { name = m.Province, value = SqlFunc.AggregateCount(m.Id)}).ToList();
        }

        public static List<ProductData> GetListByProvince(string province, int searchPage, ref int totalPage) 
        {
            //return DataBase.Instance.Queryable<ProductData>().OrderBy(x => x.Id)
            //    .ToPageList(searchPage, Constants.PageSize, ref totalPage);
            return DataBase.Instance.Queryable<ProductData>()
                .With(SqlWith.NoLock)
                .Where(x => x.Province == province)
                .ToList();
        }
    }
}
